package com.reebake.ideal.permission.controller.client;

import cn.hutool.core.util.ObjUtil;
import com.reebake.ideal.permission.client.SecurityMetadataSourceClient;
import com.reebake.ideal.permission.service.PermissionAuthService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

@Controller
@RequestMapping(value = "/permission/metadata-source")
public class SecurityMetadataSourceClientController implements SecurityMetadataSourceClient {
    @Autowired
    private PermissionAuthService permissionAuthService;

    @Override
    public Map<String, Set<String>> load() {
        Map<String, Set<String>> metadata = permissionAuthService.loadMetadata();
        if(ObjUtil.isNull(metadata)) {
            metadata = new HashMap<>();
        }
        return metadata;
    }
}
